from typing import List

from tqdm import tqdm

from bean.Constants import Constants
from bean.TableInfo import TableInfo
from builder.MapperBuilder import MapperBuilder
from utils.DatabaseUtils import DatabaseUtils
from builder import *

if __name__ == "__main__":
    with DatabaseUtils(
            host="localhost",
            port=Constants.get_instance().DATABASE_PORT,
            user=Constants.get_instance().DATABASE_USER,
            password=Constants.get_instance().DATABASE_PASSWORD,
            database=Constants.get_instance().DATABASE_NAME
    ) as databaseUtils:
        table_infos: List[TableInfo] = databaseUtils.get_table_infos()

    BaseBuilder.execute_build()
    with tqdm(total=len(table_infos), desc="构建代码", leave=True) as f:
        for i in table_infos:
            print(f"------{i.table_name}------")
            print("po构建")
            PoBuilder.execute_build(i)
            print("query构建")
            QueryBuilder.execute_build(i)
            print("mapper构建")
            MapperBuilder.execute_build(i)
            print("xml构建")
            MapperXmlBuilder.execute_build(i)
            print("service构建")
            ServiceBuilder.execute_build(i)
            print("serviceImp构建")
            ServiceImplBuilder.execute_build(i)
            print("Control")
            ControllerBuilder.execute_build(i)
            f.update(1)
    print("------构建完成！------")

    input("按Enter退出")
